﻿@using BlazorDemo.Configuration
@inject DemoConfiguration Configuration
<DxTreeView @ref="@treeView"
            CssClass="app-sidebar"
            ExpandButtonIconCssClass="demo-icon-expand"
            CollapseButtonIconCssClass="demo-icon-collapse"
            AllowSelectNodes="true"
            NodeExpandCollapseAction="TreeViewNodeExpandCollapseAction.NodeClick"
            BeforeExpand="@BeforeExpand"
            SelectionChanged="@SelectionChanged">
    <Nodes>
        <DxTreeViewNode Text="Overview" NavigateUrl="">
        </DxTreeViewNode>
        <DxTreeViewNode Text="Data Grid" BadgeText="Upd">
            <Nodes>
                <DxTreeViewNode Text="Column Types" NavigateUrl="GridColumnTypes"></DxTreeViewNode>
                <DxTreeViewNode Text="Sort Data" NavigateUrl="GridSortData"></DxTreeViewNode>
                <DxTreeViewNode Text="Group Data" NavigateUrl="GridGrouping"></DxTreeViewNode>
                <DxTreeViewNode Text="Edit Data" NavigateUrl="GridEditData" BadgeText="New"></DxTreeViewNode>
                <DxTreeViewNode Text="Filter Row" NavigateUrl="GridFilterRow"></DxTreeViewNode>
                <DxTreeViewNode Text="Selection" NavigateUrl="GridSelection"></DxTreeViewNode>
                <DxTreeViewNode Text="Templates" NavigateUrl="GridTemplate"></DxTreeViewNode>
                <DxTreeViewNode Text="Paging and Scrolling" NavigateUrl="GridPagingAndScrolling"></DxTreeViewNode>
                <DxTreeViewNode Text="Cascading Editors" NavigateUrl="GridCascadingEditors"></DxTreeViewNode>
                <DxTreeViewNode Text="Edit Form Validation" NavigateUrl="GridEditFormTemplateValidation"></DxTreeViewNode>
                <DxTreeViewNode Text="Remote Data Source" NavigateUrl="GridRemoteDataSource" />
                <DxTreeViewNode Text="Large Data Source" NavigateUrl="GridLargeDataBase" />
                <DxTreeViewNode Text="Master-Detail View" NavigateUrl="GridMasterDetail"></DxTreeViewNode>
                <DxTreeViewNode Text="HTML Decoration" NavigateUrl="GridHTMLDecoration"></DxTreeViewNode>
                <DxTreeViewNode Text="Toolbar" NavigateUrl="GridToolbar"></DxTreeViewNode>
                <DxTreeViewNode Text="Column Chooser" NavigateUrl="GridColumnChooser"></DxTreeViewNode>
            </Nodes>
        </DxTreeViewNode>
        <DxTreeViewNode Text="Pivot Grid">
            <Nodes>
                <DxTreeViewNode Text="Overview" NavigateUrl="PivotGrid"></DxTreeViewNode>
                <DxTreeViewNode Text="Templates" NavigateUrl="PivotGridTemplates"></DxTreeViewNode>
                <DxTreeViewNode Text="Large Data Source" NavigateUrl="PivotGridLargeDataBase"></DxTreeViewNode>
                <DxTreeViewNode Text="Chart Integration" NavigateUrl="PivotGridChartIntegration"></DxTreeViewNode>
            </Nodes>
        </DxTreeViewNode>
        <DxTreeViewNode Text="Charts">
            <Nodes>
                <DxTreeViewNode Text="Series Types" NavigateUrl="ChartSeriesTypes"></DxTreeViewNode>
                <DxTreeViewNode Text="Dynamic Series" NavigateUrl="ChartDynamicSeries"></DxTreeViewNode>
                <DxTreeViewNode Text="Range Series" NavigateUrl="ChartRangeSeries"></DxTreeViewNode>
                <DxTreeViewNode Text="Financial Series" NavigateUrl="ChartFinancialSeries"></DxTreeViewNode>
                <DxTreeViewNode Text="Pie Series" NavigateUrl="ChartPieSeries"></DxTreeViewNode>
                <DxTreeViewNode Text="Axes" NavigateUrl="ChartAxes"></DxTreeViewNode>
                <DxTreeViewNode Text="Customization" NavigateUrl="ChartCustomization"></DxTreeViewNode>
                <DxTreeViewNode Text="Series Customization" NavigateUrl="ChartSeriesCustomization"></DxTreeViewNode>
            </Nodes>
        </DxTreeViewNode>
        @if (Configuration.IsReportingModuleLoaded)
        {
            <DxTreeViewNode Text="Reports">
                <Nodes>
                    <DxTreeViewNode Text="Document Viewer" NavigateUrl="DocumentViewer" />
                    <DxTreeViewNode Text="Report Designer" NavigateUrl="ReportDesigner" />
                </Nodes>
            </DxTreeViewNode>
        }
        <DxTreeViewNode Text="Scheduler" BadgeText="Upd">
            <Nodes>
                <DxTreeViewNode Text="View Types" NavigateUrl="SchedulerViewTypes"></DxTreeViewNode>
                <DxTreeViewNode Text="Recurring Appointments" NavigateUrl="SchedulerRecurringAppointments"></DxTreeViewNode>
                <DxTreeViewNode Text="Templates" NavigateUrl="SchedulerTemplates" BadgeText="New"></DxTreeViewNode>
            </Nodes>
        </DxTreeViewNode>
        <DxTreeViewNode Text="Data Editors" BadgeText="Upd">
            <Nodes>
                <DxTreeViewNode Text="Calendar" NavigateUrl="Calendar">
                </DxTreeViewNode>
                <DxTreeViewNode Text="CheckBox" NavigateUrl="CheckBox">
                </DxTreeViewNode>
                <DxTreeViewNode Text="ComboBox" NavigateUrl="ComboBox" BadgeText="Upd">
                </DxTreeViewNode>
                <DxTreeViewNode Text="Date Edit" NavigateUrl="DateEdit" BadgeText="Upd">
                </DxTreeViewNode>
                <DxTreeViewNode Text="List Box" NavigateUrl="ListBox" BadgeText="Upd">
                </DxTreeViewNode>
                <DxTreeViewNode Text="Memo" NavigateUrl="Memo" BadgeText="New">
                </DxTreeViewNode>
                <DxTreeViewNode Text="Spin Edit" NavigateUrl="SpinEdit">
                </DxTreeViewNode>
                <DxTreeViewNode Text="TagBox" NavigateUrl="TagBox" BadgeText="Upd">
                </DxTreeViewNode>
                <DxTreeViewNode Text="Text Box" NavigateUrl="TextBox">
                </DxTreeViewNode>
            </Nodes>
        </DxTreeViewNode>
        <DxTreeViewNode Text="Buttons">
            <Nodes>
                <DxTreeViewNode Text="Button" NavigateUrl="Button"></DxTreeViewNode>
            </Nodes>
        </DxTreeViewNode>
        <DxTreeViewNode Text="Navigation and Layout" BadgeText="Upd">
            <Nodes>
                <DxTreeViewNode Text="Context Menu" NavigateUrl="ContextMenu">
                </DxTreeViewNode>
                <DxTreeViewNode Text="Form Layout" NavigateUrl="FormLayout">
                </DxTreeViewNode>
                <DxTreeViewNode Text="Pager" NavigateUrl="Pager">
                </DxTreeViewNode>
                <DxTreeViewNode Text="Popup" NavigateUrl="Popup">
                </DxTreeViewNode>
                <DxTreeViewNode Text="Tabs" NavigateUrl="Tabs" BadgeText="Upd">
                </DxTreeViewNode>
                <DxTreeViewNode Text="Toolbar" NavigateUrl="Toolbar">
                </DxTreeViewNode>
                <DxTreeViewNode Text="TreeView" NavigateUrl="TreeView">
                </DxTreeViewNode>
            </Nodes>
        </DxTreeViewNode>
        <DxTreeViewNode Text="File Management">
            <Nodes>
                <DxTreeViewNode Text="Upload" NavigateUrl="Upload"></DxTreeViewNode>
            </Nodes>
        </DxTreeViewNode>
        <DxTreeViewNode Text="Form Validation" NavigateUrl="FormValidation">
        </DxTreeViewNode>
    </Nodes>
</DxTreeView>

@code {
    DxTreeView treeView;

    protected void SelectionChanged(TreeViewNodeEventArgs e) {
        if (e.NodeInfo.IsLeaf) {
            var parentInfo = e.NodeInfo.Parent;
            if (parentInfo != null) {
                var parentSiblingNodesInfo = treeView.GetNodesInfo(n => !n.IsLeaf && n.Level == parentInfo.Level && !string.Equals(n.Text, parentInfo.Text));
                foreach (var nodeInfo in parentSiblingNodesInfo)
                    treeView.SetNodeExpanded(n => string.Equals(n.Text, nodeInfo.Text), false);
            }
            else
                treeView.CollapseAll();
        }
    }

    protected void BeforeExpand(TreeViewNodeCancelEventArgs e) {
        if (!e.CausedByAPI)
            treeView.CollapseAll();
    }

     bool IsDebug() {
#if DEBUG
            return true;
#else
            return false;
#endif
    }

}
